﻿using System.Collections;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

namespace THANHTUNGO.Portal.Components.Security
{
    public class Permission
    {
        public static int Insert(SqlTransaction transaction, int roleID, int moduleID, string functionID)
        {
            string spName = "[dbo].p_SYSTEM_Permission_Insert";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@RoleID", SqlDbType.Int, roleID);
            db.AddInParameter(dbCommand, "@FunctionID", SqlDbType.VarChar, functionID);
            db.AddInParameter(dbCommand, "@ModuleID", SqlDbType.Int, moduleID);
            return db.ExecuteNonQuery(dbCommand, transaction);
        }

        public static int Delete(SqlTransaction transaction, int roleID, int moduleID)
        {
            string spName = "[dbo].p_SYSTEM_Permission_DeleteBy_RoleID_ModuleID";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);
            db.AddInParameter(dbCommand, "@RoleID", SqlDbType.Int, roleID);
            db.AddInParameter(dbCommand, "@ModuleID", SqlDbType.Int, moduleID);
            return db.ExecuteNonQuery(dbCommand, transaction);
        }


    }
}